package com.aw.guiguzi.module.manager._user.presenters

import com.aw.baselib.base.AwCommonPresenter
import com.aw.baselib.net.callback.AwApiCallback
import com.aw.guiguzi.bean.UserInfoBean
import com.aw.guiguzi.module.manager._user.views.UserDetailView
import com.aw.guiguzi.net.observers.NetObCommon

/**
 * @author : hzw
 */
class UserDetailPresent(private val mView: UserDetailView.View) : AwCommonPresenter(),
    UserDetailView.Presenter {
    override fun getUserDetail(id: String?) {
        addIOSubscription(
            NetObCommon.getUserDetail(id),
            object : AwApiCallback<UserInfoBean>(mView, true, true) {
                override fun onSuccess(result: UserInfoBean) {
                    mView.getUserDetailSuccess(result)
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.getUserDetailFail(code, msg)
                }
            })
    }

    override fun updateStatus(id: String?, isEnable: Boolean) {
        addIOSubscription(
            NetObCommon.updateStatus(id, isEnable),
            object : AwApiCallback<Boolean>(mView, true, true) {
                override fun onSuccess(result: Boolean) {
                    mView.updateStatusSuccess()
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.updateStatusFail(code, msg)
                }
            })
    }

    override fun delUser(id: String?) {
        addIOSubscription(
            NetObCommon.delUser(id),
            object : AwApiCallback<Boolean>(mView, true, true) {
                override fun onSuccess(result: Boolean) {
                    mView.delUserSuccess()
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.showMsg(msg)
                }
            })
    }
}